package boss.portal.common;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

@JsonSerialize
@Data
public class ResponseData<T> {

    // request success default code
    public final static int SUCCESS_CODE = 200;
    // request error default message
    public final static int ERROR_CODE = 500;

    public final static int NO_EXIST = 403;
    // request success default message
    public final static String SUCCESS_MSG_DEFAULT = "request success";
    // request fail default message
    public final static String ERROR_MSG_DEFAULT = "request error";
    // return code
    private int code;
    // return message
    private String msg;
    // return data
    private T data;

    private boolean success = true;

    /**
     * success
     *
     * @return
     */
    public static ResponseData success() {
        ResponseData responseData = new ResponseData();
        responseData.setCode(SUCCESS_CODE);
        responseData.setMsg(SUCCESS_MSG_DEFAULT);
        return responseData;
    }

    public static ResponseData success(Object data) {
        ResponseData responseData = new ResponseData();
        responseData.setCode(SUCCESS_CODE);
        responseData.setMsg(SUCCESS_MSG_DEFAULT);
        responseData.setData(data);
        return responseData;
    }

    /**
     * fail
     *
     * @return
     */
    public static ResponseData failure() {
        ResponseData responseData = new ResponseData();
        responseData.setCode(ERROR_CODE);
        responseData.setMsg(ERROR_MSG_DEFAULT);
        return responseData;
    }

    public static ResponseData failure(Object data) {
        ResponseData responseData = new ResponseData();
        responseData.setCode(ERROR_CODE);
        responseData.setMsg(ERROR_MSG_DEFAULT);
        responseData.setData(data);
        return responseData;
    }

    public static ResponseData noexist() {
        ResponseData responseData = new ResponseData();
        responseData.setCode(NO_EXIST);
        return responseData;
    }
}
